/**
 * @ Author: luoqi
 * @ Create Time: 2024-07-11 18:28
 * @ Modified by: luoqi
 * @ Modified time: 2025-07-11 00:40
 * @ Description:
 */

#ifndef _BSP_H
#define _BSP_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdarg.h>

#include <main.h>
#include <gpio.h>
#include <tim.h>
#include <dma.h>
#include <spi.h>
#include <usb_otg.h>
#include <usb_device.h>
#include <usbd_cdc_if.h>
#include <qtask.h>

#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif

#ifndef QNULL
#define QNULL ((void *)0)
#endif

#define CCMRAM __attribute__((section(".ccmram")))

typedef enum {
    BSP_LED_OFF = 0,
    BSP_LED_ON = 1,
} BspLedState;

typedef enum {
    LED_BLINK = 0,
    LED_LINK,
    LED_ERROR,
} BspLed;

int bsp_init(void);

int bsp_deinit(void);

void bsp_led_set(BspLed led, BspLedState state);

void bsp_blink_set(size_t lfrq, size_t hfrq);

int bsp_send(const void *buf, size_t len, size_t timeout);

int bsp_recv(void *buf, size_t len, size_t timeout);

int kprintf(const char *fmt, ...);

void bsp_delay_ms(size_t ms);

void bsp_reboot(void);

int bsp_task_add(const char *name, QTaskHandle hdl, size_t period);

int bsp_task_del(const char *name);

int bsp_task_suspend(const char *name);

int bsp_task_resume(const char *name);

void bsp_task_exec();

size_t ktime(void);

void *qmalloc(size_t size);

void qfree(void *ptr);

#ifdef __cplusplus
}
#endif
#endif
